<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>jQuery Ajax</title>
    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script>
</head>
<body>
    <div>
        请输入用户名：<input type="text" id="username" value="15623301903"/>
    </div>
    <div>
        请输入密码：<input type="text" id="password" value="password"/>
    </div>
    <div>
        <button id="btn1">登录</button>
    </div>

    <div>
        <button id="btn2">验证token</button>
    </div>



    <div id="result">

    </div>
</body>
<script type="text/javascript">
    $(document).ready(function(){
        var token;
        $("#btn1").click(function(){
            var name=$("#username").val();
            var pwd=$("#password").val();
            console.log(name,pwd);

            $.ajax({
                type: 'post',
                // url: 'http://api.login.edu365.pub/login-jwt.php',
                // url: 'http://localhost:8099/user/login',
                url: 'http://dorm.abc.com/login',
                contentType:'application/x-www-form-urlencoded',
                dataType: 'json',
                data: {
                    username:　name,
                    password:　pwd
                },
                success: function(data) {
                    console.log(data)
                    if(data.status == 1) {
                        alert('登录成功');
                        $("#result").text("登录成功!");
                        token = data.token;
                        // sessionStorage.token = token;
                        // localStorage.token = token;
                    } else {
                        alert('登录失败' + data.msg);
                        $("#result").text("用户名或密码错误!");
                    }
                },
                error: function() {
                    alert('参数错误！');
                    $("#result").text("用户名或密码错误!");
                }
            });


        });

        $("#btn2").click(function(){

            console.log(token);

            $.ajax({
                type: 'post',
                // url: 'http://api.login.edu365.pub/verify-token.php',
                // url: 'http://localhost:8098/verify',
                url: 'http://jwt.abc.com/verify',
                contentType:'application/x-www-form-urlencoded',
                dataType: 'json',
                data: {
                    token:　token
                },
                success: function(data) {
                    console.log(data)
                },
                error: function() {
                    alert('参数错误！');
                }
            });


        });
    });
</script>
</html>